package com.cu.employmentmanagementsystem.service.impl;

import com.cu.employmentmanagementsystem.entity.StudentRecruitment;
import com.cu.employmentmanagementsystem.dao.StudentRecruitmentDao;
import com.cu.employmentmanagementsystem.service.StudentRecruitmentService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 简历-招聘信息对应表(StudentRecruitment)表服务实现类
 *
 * @author makejava
 * @since 2024-07-01 15:46:08
 */
@Service("studentRecruitmentService")
public class StudentRecruitmentServiceImpl implements StudentRecruitmentService {
    @Resource
    private StudentRecruitmentDao studentRecruitmentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public StudentRecruitment queryById(Long id) {
        return this.studentRecruitmentDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param studentRecruitment 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<StudentRecruitment> queryByPage(StudentRecruitment studentRecruitment, PageRequest pageRequest) {
        long total = this.studentRecruitmentDao.count(studentRecruitment);
        return new PageImpl<>(this.studentRecruitmentDao.queryAllByLimit(studentRecruitment, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param studentRecruitment 实例对象
     * @return 实例对象
     */
    @Override
    public StudentRecruitment insert(StudentRecruitment studentRecruitment) {
        this.studentRecruitmentDao.insert(studentRecruitment);
        return studentRecruitment;
    }

    /**
     * 修改数据
     *
     * @param studentRecruitment 实例对象
     * @return 实例对象
     */
    @Override
    public StudentRecruitment update(StudentRecruitment studentRecruitment) {
        this.studentRecruitmentDao.update(studentRecruitment);
        return this.queryById(studentRecruitment.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.studentRecruitmentDao.deleteById(id) > 0;
    }
}
